
Public Class CongenitalDisease

    Protected _congenital_disease_id As Integer
    Protected _congenital_disease_name_tha As String
    Protected _congenital_disease_name_eng As String
    Protected _Data As ArrayList
    Protected _DataCurrent As Integer

    Public Sub New()
        'LoadCongenitalDiseaseAll()
    End Sub

    Public Property congenital_disease_id() As Integer
        Get
            Return _congenital_disease_id
        End Get
        Set(ByVal value As Integer)
            _congenital_disease_id = value
        End Set
    End Property

    Public Property congenital_disease_name_tha() As String
        Get
            Return _congenital_disease_name_tha
        End Get
        Set(ByVal value As String)
            _congenital_disease_name_tha = value
        End Set
    End Property

    Public Property congenital_disease_name_eng() As String
        Get
            Return _congenital_disease_name_eng
        End Get
        Set(ByVal value As String)
            _congenital_disease_name_eng = value
        End Set
    End Property

    Public Sub LoadCongenitalDiseaseAll()
        _Data = New ArrayList
        _DataCurrent = 0
        _Data = getAllCongenitalDisease()
    End Sub


    Public Function getCongenitalDiseaseAll() As DataSet
        Dim decryptText As New DateUtilities.Encrypt_Data()
        Dim objConn As New MySql.Data.MySqlClient.MySqlConnection( _
            decryptText.getDecrypt(System.Configuration.ConfigurationManager.ConnectionStrings( _
            "PoliceHealthConnectionString").ToString(), True))
        Dim objCmd As New MySql.Data.MySqlClient.MySqlCommand()
        objCmd.Connection = objConn
        objCmd.CommandType = CommandType.StoredProcedure
        objCmd.CommandText = "proc_SELECT_CongenitalDiseaseAll"

        Dim objDa As New MySql.Data.MySqlClient.MySqlDataAdapter(objCmd)
        Dim objDs As New System.Data.DataSet()
        objDa.Fill(objDs, "trcongenital_disease")

        Return objDs
    End Function

    Protected Function getAllCongenitalDisease() As ArrayList
        Dim outResult As New ArrayList()
        Dim decryptText As New DateUtilities.Encrypt_Data()
        Dim objConn As New MySql.Data.MySqlClient.MySqlConnection( _
            decryptText.getDecrypt(System.Configuration.ConfigurationManager.ConnectionStrings( _
            "PoliceHealthConnectionString").ToString(), True))
        Dim objCmd As New MySql.Data.MySqlClient.MySqlCommand()
        objCmd.Connection = objConn
        objCmd.CommandType = CommandType.StoredProcedure
        objCmd.CommandText = "proc_SELECT_CongenitalDiseaseAll"

        Dim objDa As New MySql.Data.MySqlClient.MySqlDataAdapter(objCmd)
        Dim objDs As New System.Data.DataSet()
        objDa.Fill(objDs, "tableCongenitalDisease")

        For Each objDr As System.Data.DataRow In objDs.Tables("tableCongenitalDisease").Rows
            Dim obj As CongenitalDisease = New CongenitalDisease
            obj.congenital_disease_id = objDr.Item("congenital_disease_id").ToString()
            obj.congenital_disease_name_tha = objDr.Item("congenital_disease_name_tha").ToString()
            obj.congenital_disease_name_eng = objDr.Item("congenital_disease_name_eng").ToString()
            outResult.Add(obj)
        Next

        Return outResult
    End Function

    Public Function NextRecord() As Boolean
        If ((Not _Data Is Nothing) AndAlso (((Not _Data Is Nothing) AndAlso _
            (_DataCurrent < _Data.Count And _Data.Count > 0)))) Then
            _congenital_disease_id = _Data(_DataCurrent).congenital_disease_id
            _congenital_disease_name_tha = _Data(_DataCurrent).congenital_disease_name_tha
            _congenital_disease_name_eng = _Data(_DataCurrent).congenital_disease_name_eng
            _DataCurrent += 1
            Return True
        End If
        Return False
    End Function

    Public Function insertCongenitalDisease(ByVal inCongenitalDisease As CongenitalDisease) As Boolean
        Try
            Dim decryptText As New DateUtilities.Encrypt_Data()
            Dim objConn As New MySql.Data.MySqlClient.MySqlConnection( _
                decryptText.getDecrypt(System.Configuration.ConfigurationManager.ConnectionStrings( _
                "PoliceHealthConnectionString").ToString(), True))
            Dim objCmd As New MySql.Data.MySqlClient.MySqlCommand()
            objCmd.Connection = objConn
            objCmd.CommandType = CommandType.StoredProcedure
            objCmd.CommandText = "proc_INSERT_CongenitalDisease"

            Dim objParam As New MySql.Data.MySqlClient.MySqlParameter("inCongenitalDiseaseID", _
                Utilities.SendToDatabase(inCongenitalDisease.congenital_disease_id))
            objCmd.Parameters.Add(objParam)

            objParam = New MySql.Data.MySqlClient.MySqlParameter("inCongenitalDiseaseNameTha", _
                Utilities.SendToDatabase(inCongenitalDisease.congenital_disease_name_tha))
            objCmd.Parameters.Add(objParam)

            objParam = New MySql.Data.MySqlClient.MySqlParameter("inCongenitalDiseaseNameEng", _
                Utilities.SendToDatabase(inCongenitalDisease.congenital_disease_name_eng))
            objCmd.Parameters.Add(objParam)

            objConn.Open()
            objCmd.ExecuteNonQuery()
            objConn.Close()

            Return True
        Catch ex As Exception
            Return False
        End Try
    End Function

    Public Function updateCongenitalDisease(ByVal inCongenitalDisease As CongenitalDisease) As Boolean
        Try
            Dim decryptText As New DateUtilities.Encrypt_Data()
            Dim objConn As New MySql.Data.MySqlClient.MySqlConnection( _
                decryptText.getDecrypt(System.Configuration.ConfigurationManager.ConnectionStrings( _
                "PoliceHealthConnectionString").ToString(), True))
            Dim objCmd As New MySql.Data.MySqlClient.MySqlCommand()
            objCmd.Connection = objConn
            objCmd.CommandType = CommandType.StoredProcedure
            objCmd.CommandText = "proc_UPDATE_CongenitalDisease"

            Dim objParam As New MySql.Data.MySqlClient.MySqlParameter("inCongenitalDiseaseID", _
                Utilities.SendToDatabase(inCongenitalDisease.congenital_disease_id))
            objCmd.Parameters.Add(objParam)

            objParam = New MySql.Data.MySqlClient.MySqlParameter("inCongenitalDiseaseNameTha", _
                Utilities.SendToDatabase(inCongenitalDisease.congenital_disease_name_tha))
            objCmd.Parameters.Add(objParam)

            objParam = New MySql.Data.MySqlClient.MySqlParameter("inCongenitalDiseaseNameEng", _
                Utilities.SendToDatabase(inCongenitalDisease.congenital_disease_name_eng))
            objCmd.Parameters.Add(objParam)

            objConn.Open()
            objCmd.ExecuteNonQuery()
            objConn.Close()

            Return True
        Catch ex As Exception
            Return False
        End Try
    End Function

    Public Function deleteCongenitalDisease(ByVal inCongenitalDisease As CongenitalDisease) As Boolean
        Try
            Dim decryptText As New DateUtilities.Encrypt_Data()
            Dim objConn As New MySql.Data.MySqlClient.MySqlConnection( _
                decryptText.getDecrypt(System.Configuration.ConfigurationManager.ConnectionStrings( _
                "PoliceHealthConnectionString").ToString(), True))
            Dim objCmd As New MySql.Data.MySqlClient.MySqlCommand()
            objCmd.Connection = objConn
            objCmd.CommandType = CommandType.StoredProcedure
            objCmd.CommandText = "proc_DELETE_CongenitalDisease"

            Dim objParam As New MySql.Data.MySqlClient.MySqlParameter("inCongenitalDiseaseID", _
                Utilities.SendToDatabase(inCongenitalDisease.congenital_disease_id))
            objCmd.Parameters.Add(objParam)

            objConn.Open()
            objCmd.ExecuteNonQuery()
            objConn.Close()

            Return True
        Catch ex As Exception
            Return False
        End Try
    End Function

End Class
